package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.AlbumAttributeValueService;
import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.common.login.AuthLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.album.AlbumAttributeValue;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.query.album.AlbumInfoVo;
import com.atguigu.tingshu.query.album.AlbumListVo;
import com.atguigu.tingshu.query.album.AlbumStatVo;
import com.atguigu.tingshu.query.album.AlbumTitleListVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.service.RequestBodyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album")
@SuppressWarnings({"all"})
public class AlbumInfoApiController {

    @Autowired
    private AlbumInfoService albumInfoService;
    @Autowired
    private RequestBodyService requestBodyBuilder;
    @Autowired
    private AlbumAttributeValueService albumAttributeValueService;


    @AuthLogin
    @Operation(summary = "新增专辑")
    @PostMapping("/albumInfo/saveAlbumInfo")
    public Result saveAlbumInfo(@Validated @RequestBody AlbumInfoVo albumInfoVo) {
        Long userId = AuthContextHolder.getUserId();
        albumInfoService.saveAlbumInfo(albumInfoVo, userId);
        return Result.ok();
    }

    @AuthLogin
    @Operation(summary = "查看当前用户专辑分页列表")
    @PostMapping("/albumInfo/findUserAlbumPage/{page}/{limit}")
    public Result<IPage<AlbumListVo>> findUserAlbumPage(
            @PathVariable Long page,
            @PathVariable Long limit,
            @RequestBody AlbumInfoQuery albumInfoQuery) {
        IPage<AlbumListVo> albumListVoIPage = new Page<>(page, limit);
        albumListVoIPage = albumInfoService.findUserAlbumPage(albumListVoIPage, albumInfoQuery);
        return Result.ok(albumListVoIPage);
    }

    @Operation(summary = "根据ID删除专辑")
    @DeleteMapping("/albumInfo/removeAlbumInfo/{id}")
    public Result removeAlbumInfo(@PathVariable Long id) {
        albumInfoService.removeAlbumInfo(id);
        return Result.ok();
    }

    @Operation(summary ="根据ID查询专辑信息")
    @GetMapping("/albumInfo/getAlbumInfo/{id}")
    public Result<AlbumInfo> getAlbumInfo(@PathVariable Long id){
        AlbumInfo albumInfo = albumInfoService.getById(id);
        return Result.ok(albumInfo);
    }

    @Operation(summary = "修改专辑")
    @PutMapping("/albumInfo/updateAlbumInfo/{id}")
    public Result updateAlbumInfo(
            @PathVariable Long id,
            @Validated @RequestBody AlbumInfoVo albumInfoVo) {
        albumInfoService.updateAlbumInfo(id,albumInfoVo);
        return Result.ok();
    }

    @AuthLogin
    @Operation(summary ="获取当前用户全部专辑列表")
    @GetMapping("/albumInfo/findUserAllAlbumList")
    public Result<List<AlbumInfo>> findUserAllAlbumList(){
        Long userId = AuthContextHolder.getUserId();
        List<AlbumInfo> albumVoList = albumInfoService.findUserAllAlbumList(userId);
        return Result.ok(albumVoList);
    }

    @Operation(summary = "获取专辑属性值列表")
    @GetMapping("/albumInfo/findAlbumAttributeValue/{albumId}")
    public Result<List<AlbumAttributeValue>> findAlbumAttributeValue(@PathVariable Long albumId){
        List<AlbumAttributeValue> albumAttributeValueList = albumAttributeValueService.findAlbumAttributeValue(albumId);
        return Result.ok(albumAttributeValueList);
    }

    @Operation(summary ="根据ID获取专辑统计信息")
    @GetMapping("/albumInfo/getAlbumStatVo/{albumId}")
    public Result<AlbumStatVo> getAlbumStatVo(@PathVariable Long albumId){
        AlbumStatVo albumStatVo = albumInfoService.getAlbumStatVo(albumId);
        return Result.ok(albumStatVo);
    }


}

